package com.test.multithread;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.concurrent.CountDownLatch;

/**
 * Created by jl on 2016/8/7.
 */
public class WriteThread extends Thread {
    private RandomAccessFile raf;
    private CountDownLatch latch;
    private long start;
    private String content;

    public WriteThread(RandomAccessFile raf, CountDownLatch latch, long start, String content) {
        this.raf = raf;
        this.latch = latch;
        this.start = start;
        this.content = content;
    }

    public void run() {
        try {
            raf.seek(start);
            raf.write(content.getBytes());
            raf.close();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            latch.countDown();
        }

    }
}
